﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShiXuLong.Service;
namespace ShiXuLong.Admin.Controllers
{
    [Authorize]
    /// <summary>
    /// 订单的控制器
    /// </summary>
    public class OrderController : Controller
    {
        Order cd = new Service.Order();
        // GET: Order
        /// <summary>
        /// 订单管理主页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 订单管理数据接口
        /// </summary>
        /// <param name="limit"></param>
        /// <param name="page"></param>
        /// <param name="userId"></param>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public ActionResult Order(int limit, int page, int userId = 0, int orderId = 0)
        {
            int count;
            var list = cd.GetOrder(limit, page, userId, orderId, out count);
            return Json(new { code = 0, msg = "", data = list, count = count }, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 点击查看打开的页面
        /// </summary>
        /// <returns></returns>
        public ActionResult CheckView(int id)
        {
            return View(id);
        }

        /// <summary>
        /// 订单详情接口
        /// </summary>
        /// <returns></returns>
        public ActionResult OrderDetail(int id)
        {
            var list = cd.GetOrderDetail(id);
            return Json(new { msg = "", code = 0, count = 10, data = list }, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 发货
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult SendOrder(int id)
        {
            int res = cd.SendOrder(id);
            if (res > 0)
            {
                return Json(new { success = res, msg = "发货成功" });

            }
            else {
                return Json(new { success = res, msg = "发货失败，网络被劫持了" });

            }
        }

    }
}